package com.example.show2page.controller;

import com.example.show2page.pojo.*;
import com.example.show2page.service.PageService;
import com.example.show2page.utils.ResultVoUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Hacah
 * @date 2021/4/23 10:19
 */
@RestController
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 表格1的查询
     *
     * @param pageVO
     * @return
     */
    @RequestMapping({"/page1"})
    public ResultVo<PageInfo<TableData>> findTableData(@RequestBody PageVO pageVO) {
        PageInfo<TableData> tableData = pageService.getTableData(pageVO);
        return ResultVoUtil.success(tableData);
    }

    /**
     * 表格2的查询
     *
     * @param tableName
     * @return
     */
    @RequestMapping({"/page1detail", "/page2detail"})
    public ResultVo<PageInfo<TableStruct>> findTableDataStruct(@RequestParam("tableName") String tableName,
                                                         @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                         @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        PageInfo<TableStruct> tableStruct = pageService.getTableStruct(tableName,pageNum, pageSize);
        return ResultVoUtil.success(tableStruct);
    }


    /**
     * 页面2的下拉列表的系统条件获取
     *
     * @return
     */
    @RequestMapping({"/page2"})
    public ResultVo<ConditionsVO> getSysCondition() {
        ConditionsVO condition = pageService.getSysCondition();
        return ResultVoUtil.success(condition);
    }

    /**
     * 页面2的下拉列表的系统选定后其他条件获取
     *
     * @return
     */
    @RequestMapping({"/page2otherCondition"})
    public ResultVo<ConditionsVO> getOtherCondition(@RequestParam(required = false) String sysName,
                                                    @RequestParam(required = false) String level1,
                                                    @RequestParam(required = false) String level2,
                                                    @RequestParam(required = false) String level3,
                                                    @RequestParam(required = false) String level4
    ) {
        ConditionsVO condition = pageService.getOtherCondition(sysName, level1, level2, level3, level4);
        return ResultVoUtil.success(condition);
    }

    /**
     * 查询页面2的表1数据
     *
     * @param sysName 系统名称
     * @param level1  一级功能名
     * @param level2  二级功能名
     * @param level3  三级功能名
     * @param level4  四级功能名
     * @return
     */
    @RequestMapping("/page2data")
    public ResultVo<PageInfo<TableData>> findTableData2(@RequestParam(required = false) String sysName,
                                                    @RequestParam(required = false) String level1,
                                                    @RequestParam(required = false) String level2,
                                                    @RequestParam(required = false) String level3,
                                                    @RequestParam(required = false) String level4,
                                                    @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                    @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        ResultVo<PageInfo<TableData>> pageInfoResultVo = ResultVoUtil.success(pageService.getTableData2(sysName, level1, level2, level3, level4, pageNum, pageSize));
        return pageInfoResultVo;
    }

}
